# _*_ coding: UTF-8 _*_
# @Time     : 2021/10/25 10:41
# @Author   : 郑鲁明
# @Site     : http://www.hzdledu.cn/
# @File     : 序列.py
# @Software : PyCharm

# 序列的操作
# 1.序列的索引操作
list1 = [1, 3, 6, 2]
tuple1 = [2, 5, 7, 8, 9]
print(list1[-1])
print(tuple1[-3])

list2 = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
]
print([list2[0][2]])

for i in list2:
    for j in i:
        print(j, end=',')
    print()

# 2.序列的切片

print('-----------------------')
list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
tuple1 = (1, 2, 3, 4, 5, 6, 7, 8, 9)
print(list1[1:2])   # [2]
print(list1[:2])    # [1,2]  0~2
print(tuple1[1:])   # [2,3,4,5,6,7,8,9]
print(tuple1[::2])  # (1, 3, 5, 7, 9)

#  3.序列的相加
lis1 = [1, 2, 3]
list2 = [4, 5, 3]
list3 = lis1 + list2
print(list3)  # [1, 2, 3, 4, 5, 3]

# 4.操作序列的函数
print('------操作序列的函数-------')
print(tuple(list1))
